package com.frame.platform.user;

import java.util.*;
import com.frame.database.DataBase;
import com.frame.database.util.ConditionMap;
import com.frame.util.MD5;

public class UserLoginOperator{

	public SessionOaUser login(String loginName,String pwd) throws LoginException,Exception{
		String password=new MD5().getMD5ofStr(pwd);
		ConditionMap pam=new ConditionMap();
		pam.put("loginname = ?").setParameter(loginName);
		pam.put("userpwd = ?").setParameter(password);
		pam.put("state <> 2");
		List list=DataBase.getInstance().query("Wfuser", pam);
		
		if(list.size()>0){
			SessionOaUser info=new SessionOaUser();
			Wfuser user=(Wfuser)list.get(0);
			if(user.getState().intValue()==0)
			    throw new LoginException("用户名被冻结，请联系管理员！");
			info.setLoginName(loginName);
			info.setUserId(user.getUserid());
			info.setUserName(user.getUsername());
			if(user.getStyle()==null || "".equals(user.getStyle()))
			    user.setStyle("default");
			info.setStyle(user.getStyle());
			return info;
		}else
			throw new LoginException("用户名或密码错误！");
	}

}
